"ui";

if (device.device == 'mido') {
    ui.layout(
        <frame bg="#101010">
            <horizontal marginTop="10">
                <text textStyle="bold" w="50" h="50" text="工号" color="#ccccccfa" />
                <input id="customer_no" hint="输入工号" textSize="16sp" w="200" h="50" color="#ffffff" />
                <button id="customer_save" w="50" h="40" text="保存" bg="#00c0ef" color="#ffffff" />
                <button marginLeft="10" id="customer_fresh" w="50" h="40" text="刷新" bg="#f39c12" color="#ffffff" />
            </horizontal>

            <vertical marginTop="60">
                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控一" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_one" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_one" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_one" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_one" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_one" text="0" color="#ccccccfa" />
                        <button id="add_one" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控二" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_two" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_two" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_two" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_two" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_two" text="0" color="#ccccccfa" />
                        <button id="add_two" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控三" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_three" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_three" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_three" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_three" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_three" text="0" color="#ccccccfa" />
                        <button id="add_three" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控四" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_four" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_four" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_four" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_four" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_four" text="0" color="#ccccccfa" />
                        <button id="add_four" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控五" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_five" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_five" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_five" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_five" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_five" text="0" color="#ccccccfa" />
                        <button id="add_five" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>


            </vertical>
            <horizontal w="auto">
                <button marginTop="550" marginLeft="120" id="save_no" textSize="18sp" w="120" h="50" padding="0" text="保存" bg="#00c0ef" color="#ffffff" />
            </horizontal>
        </frame>
    );
} else if (device.device == 'le_x620') {
    ui.layout(
        <frame bg="#101010">
            <horizontal marginTop="10">
                <text textStyle="bold" w="50" h="50" text="工号" color="#ccccccfa" />
                <input id="customer_no" hint="输入工号" textSize="16sp" w="250" h="50" color="#ffffff" />
                <button id="customer_save" w="50" h="40" text="保存" bg="#00c0ef" color="#ffffff" />
                <button marginLeft="10" id="customer_fresh" w="50" h="40" text="刷新" bg="#f39c12" color="#ffffff" />
            </horizontal>

            <vertical marginTop="80">
                <vertical>
                    <horizontal marginTop="20">
                        <text textStyle="bold" w="50" h="50" text="主控一" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="100" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_one" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="15" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="30" id="clear_one" w="60" h="30" padding="0" textSize="13sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_one" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_one" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="35" w="35" h="50" id="free_one" text="0" color="#ccccccfa" />
                        <button id="add_one" marginLeft="24" w="60" h="30" padding="0" textSize="13sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="20">
                        <text textStyle="bold" w="50" h="50" text="主控二" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="100" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_two" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="15" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="30" id="clear_two" w="60" h="30" padding="0" textSize="13sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_two" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_two" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="35" w="35" h="50" id="free_two" text="0" color="#ccccccfa" />
                        <button id="add_two" marginLeft="24" w="60" h="30" padding="0" textSize="13sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="20">
                        <text textStyle="bold" w="50" h="50" text="主控三" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="100" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_three" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="15" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="30" id="clear_three" w="60" h="30" padding="0" textSize="13sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_three" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_three" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="35" w="35" h="50" id="free_three" text="0" color="#ccccccfa" />
                        <button id="add_three" marginLeft="24" w="60" h="30" padding="0" textSize="13sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="20">
                        <text textStyle="bold" w="50" h="50" text="主控四" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="100" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_four" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="15" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="30" id="clear_four" w="60" h="30" padding="0" textSize="13sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_four" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_four" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="35" w="35" h="50" id="free_four" text="0" color="#ccccccfa" />
                        <button id="add_four" marginLeft="24" w="60" h="30" padding="0" textSize="13sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="20">
                        <text textStyle="bold" w="50" h="50" text="主控五" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="100" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_five" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="15" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="30" id="clear_five" w="60" h="30" padding="0" textSize="13sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_five" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_five" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="35" w="35" h="50" id="free_five" text="0" color="#ccccccfa" />
                        <button id="add_five" marginLeft="24" w="60" h="30" padding="0" textSize="13sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

            </vertical>
            <horizontal w="auto">
                <button marginTop="630" marginLeft="150" id="save_no" textSize="18sp" padding="0" w="120" h="50" text="保存" bg="#00c0ef" color="#ffffff" />
            </horizontal>
        </frame>
    );
} else {
    toast('未适配机型');
    ui.layout(
        <frame bg="#101010">
            <horizontal marginTop="10">
                <text textStyle="bold" w="50" h="50" text="工号" color="#ccccccfa" />
                <input id="customer_no" hint="输入工号" textSize="16sp" w="200" h="50" color="#ffffff" />
                <button id="customer_save" w="50" h="40" text="保存" bg="#00c0ef" color="#ffffff" />
                <button marginLeft="10" id="customer_fresh" w="50" h="40" text="刷新" bg="#f39c12" color="#ffffff" />
            </horizontal>

            <vertical marginTop="60">
                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控一" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_one" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_one" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_one" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_one" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_one" text="0" color="#ccccccfa" />
                        <button id="add_one" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控二" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_two" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_two" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_two" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_two" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_two" text="0" color="#ccccccfa" />
                        <button id="add_two" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控三" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_three" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_three" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_three" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_three" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_three" text="0" color="#ccccccfa" />
                        <button id="add_three" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控四" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_four" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_four" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_four" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_four" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_four" text="0" color="#ccccccfa" />
                        <button id="add_four" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>

                <vertical>
                    <horizontal marginTop="10">
                        <text textStyle="bold" w="50" h="50" text="主控五" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="40" w="80" h="50" text="累计点赞" color="#ccccccfa" />
                        <text id="support_five" textStyle="bold" marginLeft="5" w="60" h="50" text="0" color="#ccccccfa" />
                        <text marginLeft="5" text="空闲" textStyle="bold" w="35" h="50" color="#ccccccfa" />
                        <button marginLeft="10" id="clear_five" padding="0" w="60" h="30" textSize="12sp" text="清零" bg="#f90e0e" color="#ffffff" />
                    </horizontal>
                    <horizontal marginTop="-15">
                        <text textStyle="bold" w="50" h="50" text="抖音号" color="#ccccccfa" />
                        <input id="machine_five" textSize="16sp" w="180" h="50" color="#ffffff" />
                        <text alpha="0" textStyle="bold" marginLeft="10" w="1" h="50" id="vis_five" text="0" color="#ccccccfa" />
                        <text textStyle="bold" marginLeft="8" w="35" h="50" id="free_five" text="0" color="#ccccccfa" />
                        <button id="add_five" marginLeft="1" w="60" h="30" padding="0" textSize="12sp" text="增加" bg="#2c974b" color="#ffffff" />
                    </horizontal>
                </vertical>


            </vertical>
            <horizontal w="auto">
                <button marginTop="550" marginLeft="120" id="save_no" textSize="18sp" w="120" h="50" padding="0" text="保存" bg="#00c0ef" color="#ffffff" />
            </horizontal>
        </frame>
    );
}

let storage = storages.create("LOCAL");
let first = true;

threads.start(function () {
    while (true) {
        let no = ui.customer_no.getText();
        if (isEmpty(no)) {
            no = storage.get('code');
            ui.run(function () {
                ui.customer_no.setText(no.toString());
            })
        }
        if (!isEmpty(no)) {
            //获取绑定状态
            let deviceId = device.getIMEI();
            if (deviceId == null) {
                deviceId = device.getAndroidId();
            }
            let res = http.get("http://dy.leyouhome.cn/api/assistant/bind?device=" + deviceId + "&c_id=" + no);
            if (res.statusCode == 200) {
                let resp = JSON.parse(res.body.string());
                if (resp.code == 200) {
                    ui.run(function () {
                        if (first) {
                            updateIputFirst(resp.data);
                            first = false;
                        } else {
                            updateIput(resp.data);
                        }
                    });
                } else {
                    toast(resp.message);
                }
            } else {
                toast('当前网络忙');
            }
        }
        sleep(10000);
    }
});

/**
 * 运行脚本
 */
ui.customer_save.click(() => {
    threads.start(function () {
        let no = ui.customer_no.getText();
        if (isEmpty(no)) {
            toast('工号不能为空');
            return;
        }
        //获取绑定状态
        let deviceId = device.getIMEI();
        if (deviceId == null) {
            deviceId = device.getAndroidId();
        }
        let res = http.get("http://dy.leyouhome.cn/api/assistant/bind?device=" + deviceId + "&c_id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                storage.put('code', no.toString());
                ui.run(function () {
                    updateIputFirst(resp.data);
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

/**
 * 刷新操作
 */
ui.customer_fresh.click(() => {
    threads.start(function () {
        let no = ui.customer_no.getText();
        if (isEmpty(no)) {
            toast('工号不能为空');
            return;
        }
        //获取绑定状态
        let deviceId = device.getIMEI();
        if (deviceId == null) {
            deviceId = device.getAndroidId();
        }
        let res = http.get("http://dy.leyouhome.cn/api/assistant/refresh?device=" + deviceId + "&c_id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                storage.put('code', no.toString());
                ui.run(function () {
                    updateIputFirst(resp.data);
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

/**
 * 增加操作
 */
ui.add_one.click(() => {
    threads.start(function () {
        let code = ui.machine_one.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_one.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/task_num?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    increaseNumber(1);
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.add_two.click(() => {
    threads.start(function () {
        let code = ui.machine_two.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_two.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/task_num?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    increaseNumber(2);
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.add_three.click(() => {
    threads.start(function () {
        let code = ui.machine_three.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_three.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/task_num?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    increaseNumber(3);
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.add_four.click(() => {
    threads.start(function () {
        let code = ui.machine_four.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_four.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/task_num?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    increaseNumber(4);
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.add_five.click(() => {
    threads.start(function () {
        let code = ui.machine_five.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_five.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/task_num?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    increaseNumber(5);
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.clear_one.click(() => {
    threads.start(function () {
        let code = ui.machine_one.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_one.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/clean?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    ui.free_one.setText("0");
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.clear_two.click(() => {
    threads.start(function () {
        let code = ui.machine_two.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_two.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/clean?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    ui.free_two.setText("0");
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.clear_three.click(() => {
    threads.start(function () {
        let code = ui.machine_three.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_three.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/clean?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    ui.free_three.setText("0");
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.clear_four.click(() => {
    threads.start(function () {
        let code = ui.machine_four.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_four.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/clean?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    ui.free_four.setText("0");
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

ui.clear_five.click(() => {
    threads.start(function () {
        let code = ui.machine_five.getText();
        if (isEmpty(code)) {
            toast('抖音号不能为空');
            return;
        }
        let no = ui.vis_five.getText();
        //获取绑定状态
        let res = http.get("http://dy.leyouhome.cn/api/assistant/clean?id=" + no);
        if (res.statusCode == 200) {
            let resp = JSON.parse(res.body.string());
            if (resp.code == 200) {
                ui.run(function () {
                    ui.free_five.setText("0");
                });
            } else {
                toast(resp.message);
            }
        } else {
            toast('当前网络忙');
        }
    });
});

/**
 * 保存抖音主号配置
 */
ui.save_no.click(() => {
    let code_one = ui.machine_one.getText();
    let id_one = ui.vis_one.getText();
    let code_two = ui.machine_two.getText();
    let id_two = ui.vis_two.getText();
    let code_three = ui.machine_three.getText();
    let id_three = ui.vis_three.getText();
    let code_four = ui.machine_four.getText();
    let id_four = ui.vis_four.getText();
    let code_five = ui.machine_five.getText();
    let id_five = ui.vis_five.getText();
    let data = [];
    if (!isEmpty(code_one) && !isEmpty(id_one)) {
        data.push({
            "id": id_one.toString(),
            "tiktok": code_one.toString()
        });
    }
    if (!isEmpty(code_two) && !isEmpty(id_two)) {
        data.push({
            "id": id_two.toString(),
            "tiktok": code_two.toString()
        });
    }
    if (!isEmpty(code_three) && !isEmpty(id_three)) {
        data.push({
            "id": id_three.toString(),
            "tiktok": code_three.toString()
        });
    }
    if (!isEmpty(code_four) && !isEmpty(id_four)) {
        data.push({
            "id": id_four.toString(),
            "tiktok": code_four.toString()
        });
    }
    if (!isEmpty(code_five) && !isEmpty(id_five)) {
        data.push({
            "id": id_five.toString(),
            "tiktok": code_five.toString()
        });
    }
    if (!isEmpty(data)) {
        log(JSON.stringify(data));
        threads.start(function () {
            let res = http.get("http://dy.leyouhome.cn/api/assistant/change?json=" + JSON.stringify(data));
            if (res.statusCode == 200) {
                let resp = JSON.parse(res.body.string());
                if (resp.code == 200) {
                    toast('更新成功');
                } else {
                    toast(resp.message);
                }
            } else {
                toast('当前网络忙');
            }
        })
    } else {
        toast('请填写抖音号');
    }
});

/**
 * 更新表单内容
 * @param {*} list 
 */
function updateIput(list) {
    if (list.length > 0) {
        for (let i = 0; i < list.length; i++) {
            if (i == 0) {
                ui.free_one.setText(list[i].video.toString());
                ui.vis_one.setText(list[i].id.toString());
                ui.support_one.setText(list[i].total.toString());
            } else if (i == 1) {
                ui.free_two.setText(list[i].video.toString());
                ui.vis_two.setText(list[i].id.toString());
                ui.support_two.setText(list[i].total.toString());
            } else if (i == 2) {
                ui.free_three.setText(list[i].video.toString());
                ui.vis_three.setText(list[i].id.toString());
                ui.support_three.setText(list[i].total.toString());
            } else if (i == 3) {
                ui.free_four.setText(list[i].video.toString());
                ui.vis_four.setText(list[i].id.toString());
                ui.support_four.setText(list[i].total.toString());
            } else if (i == 4) {
                ui.free_five.setText(list[i].video.toString());
                ui.vis_five.setText(list[i].id.toString());
                ui.support_five.setText(list[i].total.toString());
            }
        }
    }
}

/**
 * 更新表单内容
 * @param {*} list 
 */
function updateIputFirst(list) {
    if (list.length > 0) {
        for (let i = 0; i < list.length; i++) {
            if (i == 0) {
                if (!isEmpty(list[i].tiktok)) {
                    ui.machine_one.setText(list[i].tiktok.toString());
                }
                ui.free_one.setText(list[i].video.toString());
                ui.vis_one.setText(list[i].id.toString());
                ui.support_one.setText(list[i].total.toString());
            } else if (i == 1) {
                if (!isEmpty(list[i].tiktok)) {
                    ui.machine_two.setText(list[i].tiktok.toString());
                }
                ui.free_two.setText(list[i].video.toString());
                ui.vis_two.setText(list[i].id.toString());
                ui.support_two.setText(list[i].total.toString());
            } else if (i == 2) {
                if (!isEmpty(list[i].tiktok)) {
                    ui.machine_three.setText(list[i].tiktok.toString());
                }
                ui.free_three.setText(list[i].video.toString());
                ui.vis_three.setText(list[i].id.toString());
                ui.support_three.setText(list[i].total.toString());
            } else if (i == 3) {
                if (!isEmpty(list[i].tiktok)) {
                    ui.machine_four.setText(list[i].tiktok.toString());
                }
                ui.free_four.setText(list[i].video.toString());
                ui.vis_four.setText(list[i].id.toString());
                ui.support_four.setText(list[i].total.toString());
            } else if (i == 4) {
                if (!isEmpty(list[i].tiktok)) {
                    ui.machine_five.setText(list[i].tiktok.toString());
                }
                ui.free_five.setText(list[i].video.toString());
                ui.vis_five.setText(list[i].id.toString());
                ui.support_five.setText(list[i].total.toString());
            }
        }
    }
}

/**
 * 增加待操作视频数量
 * @param {*} num
 */
function increaseNumber(num) {
    let newNum;
    let newSupport;
    switch (num) {
        case 1:
            newNum = Number(ui.free_one.getText()) + 5;
            ui.free_one.setText(newNum.toString());
            newSupport = Number(ui.support_one.getText()) + 5;
            ui.support_one.setText(newSupport.toString());
            break;
        case 2:
            newNum = Number(ui.free_two.getText()) + 5;
            ui.free_two.setText(newNum.toString());
            newSupport = Number(ui.support_two.getText()) + 5;
            ui.support_two.setText(newSupport.toString());
            break;
        case 3:
            newNum = Number(ui.free_three.getText()) + 5;
            ui.free_three.setText(newNum.toString());
            newSupport = Number(ui.support_three.getText()) + 5;
            ui.support_three.setText(newSupport.toString());
            break;
        case 4:
            newNum = Number(ui.free_four.getText()) + 5;
            ui.free_four.setText(newNum.toString());
            newSupport = Number(ui.support_four.getText()) + 5;
            ui.support_four.setText(newSupport.toString());
            break;
        case 5:
            newNum = Number(ui.free_five.getText()) + 5;
            ui.free_five.setText(newNum.toString());
            newSupport = Number(ui.support_five.getText()) + 5;
            ui.support_five.setText(newSupport.toString());
            break;
    }
}

function isEmpty(obj) {
    if (typeof obj == "undefined" || obj == null || obj == "") {
        return true;
    } else {
        return false;
    }
}